﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

public partial class Clients_ViSaPage : System.Web.UI.MasterPage
{
    private String strTop = "<li class='tab_$idTabs'><a href='" + Constant.ROOT_PATH + "$link'><span>$text</span></a></li>";
    private String strBottom = "<a href='" + Constant.ROOT_PATH + "$link' class='footer_menu_link'>$text</a>";
    private String strQuangCao = "<div style='margin-top: 1px;'><a href='$link' target='_blank'><img class='ads_item' src='" + Constant.ROOT_PATH + "$src' /></a></div>";
    protected void Page_Load(object sender, EventArgs e)
    {
        String strPage = "";
        try
        {
            strPage = Request.Params["Pro"].ToString().Trim();
        }
        catch
        {

        }
        String[] arrPage = strPage.Split('_');

        if (!this.IsPostBack)
        {
            String sTabs = "77";
            if(arrPage.Length>=2){
                sTabs = arrPage[1];
            }
            LoadDataCategory("tab_"+sTabs);
            LoadQuangCao();
            LoadLink();
            LoadDataYahoo();

        }
        
        
       // lblJQuery.Text = strQuery;
    }


    private void LoadLink()
    {

        using (WebData data = new WebData())
        {
            List<DataLibrary.tbl_Weblink> list = data.tbl_Weblinks.GetListCache("weblink", Constant.time);
            this.drlLink.DataSource = list;
            this.drlLink.DataValueField = "Url";
            this.drlLink.DataTextField = "Title";
            this.drlLink.DataBind();
            this.drlLink.Items.Insert(0, new ListItem("------- Liên kết website --------", "0"));
            
        }
    }

    private void LoadDataYahoo()
    {

        using (WebData db = new WebData())
        {
            List<DataLibrary.tbl_Nick_Yahoo> list = db.tbl_Nick_Yahoos.GetListCache("nick_yahoo", Constant.time);
        }
    }

    private void LoadDataCategory(String idTabs)
    {
        String url = "";
        String urlBottom = "";


        using (WebData data = new WebData())
        {
            DataTable tb = data.tbl_Categorys.GetDataTableCache("category", Constant.time, "GetCategory",
                CommandType.StoredProcedure);

            foreach (DataRow row in tb.Rows)
            {
                String sUrl = String.Format("{0}_{1}", row["FriendlyUrl"], row[0]);
                url = url + strTop.Replace("$text", row["nameCat"].ToString()).Replace("$link",
                    sUrl.Replace("~/", "").Replace(".aspx", "")).Replace("$idTabs", row[0].ToString()).Replace(idTabs, "selected");

                if (!string.IsNullOrEmpty(urlBottom))
                {
                    urlBottom += " | ";
                }
                urlBottom = urlBottom + strBottom.Replace("$text", row["nameCat"].ToString()).Replace("$link",
                    sUrl.Replace("~/", "").Replace(".aspx", ""));
            }
            
        }
        this.lblmenutabs.Text = url;
        this.bottom.Text = urlBottom +"<br/>";

    }

    private void LoadQuangCao()
    {
        using (WebData data = new WebData())
        {
            List<DataLibrary.tbl_Quangcao> list = data.tbl_Quangcaos.GetAll().FindAll(p => p.IsActive == 1);
            String url = "";
            foreach (DataLibrary.tbl_Quangcao obj in list)
            {
                url = url + strQuangCao.Replace("$link", obj.UrlQuangcao).Replace("$src", obj.Image);
            }
            lblQuangCao.Text = url;
        }
    }
}
